package de.openkanban.client.ui.presenter;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import com.google.gwt.json.client.JSONArray;
import com.smartgwt.client.util.JSON;

import de.openkanban.client.ui.board.ActivityView;
import de.openkanban.shared.dto.KanbanDto;

public class GetKanbansByActivityIdRequestCallback implements RequestCallback {

	private ActivityView activityView;

	public GetKanbansByActivityIdRequestCallback(ActivityView activityView) {
		this.activityView = activityView;
	}

	@Override
	public void onResponseReceived(Request request, Response response) {
		JSONArray jsa = new JSONArray(JSON.decode(response.getText()));
		KanbanDto kanbanDto;
		for (int i = 0; i < jsa.size(); i++) {
			kanbanDto = new KanbanDto(jsa.get(i).isObject().toString());
			activityView.addKanban(kanbanDto);
		}
	}

	@Override
	public void onError(Request request, Throwable exception) {

	}

}
